<?php
$GLOBALS['BIG_CAT_ID'] = 1;
$dt = new DataTable(constant('DB_TABLE_ARTICLE_META'));
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if ( $act == 'save' ) {
	foreach($GLOBALS['GV_ARTICLE_SUB_CAT'][$GLOBALS['BIG_CAT_ID']] as $sub_cat_id=>$nouse)
	{
		$row = $dt->get_row(sprintf("`article_cat_id`=%d AND `article_sub_cat_id`=%d", $GLOBALS['BIG_CAT_ID'], $sub_cat_id));
		if ( !$row ) {
			$row = array(
					'article_cat_id'=> $GLOBALS['BIG_CAT_ID'],
					'article_sub_cat_id'=>$sub_cat_id,
					'meta_keyword'=>'',
					'meta_description'=>''
					);
		}
		$req_parm_key = 'meta_keyword_'.$sub_cat_id;
		if ( isset($_REQUEST[$req_parm_key]) AND is_array($_REQUEST[$req_parm_key]) ) {
			$row['meta_keyword'] = implode(',', $_REQUEST[$req_parm_key] );
		}else{
			$row['meta_keyword'] = '';
		}
		$req_parm_key = 'meta_description_'.$sub_cat_id;
		$row['meta_description'] = $_REQUEST[$req_parm_key];
		$dt->save($row);
	}
}
$condition = sprintf("`article_cat_id`=%d",$GLOBALS['BIG_CAT_ID']);
$list_data = $dt->get_list($condition);
$GLOBALS['PAGE_FORM_DATA'] = array();
foreach($GLOBALS['GV_ARTICLE_SUB_CAT'][$GLOBALS['BIG_CAT_ID']] as $sub_cat_id=>$nouse)
{
	$GLOBALS['PAGE_FORM_DATA'][$sub_cat_id] = array('meta_keyword'=>array(), 'meta_description'=>'');
}
foreach($list_data as $row)
{
	$meta_data = array();
	$meta_data['meta_keyword'] = $row['meta_keyword'];
	$meta_data['meta_keyword'] = explode(',',$meta_data['meta_keyword'] );
	$meta_data['meta_description'] = $row['meta_description'];
	$GLOBALS['PAGE_FORM_DATA'][$row['article_sub_cat_id']] = $meta_data;
}
?>